﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using AutoCode.Win;

namespace EZ.Open.AutoCode
{
    public class ProjectFileHelper
    {
        private string FileName;//项目文件名
        private string Ext = ".csproj";//EZ.Open.BLL.csproj
        private string Path = "";
        public ProjectFileHelper(string filename)
        {
            FileName = filename;
            Path = Config.Dir + "/" + filename + "/" + filename + Ext;
        }

        public void TryAddcs(string dir,string file)
        {
            string content = File.ReadAllText(Path, Encoding.UTF8);
            string tag =string.Format( "<Compile Include=\"{0}\\{1}\" />",dir,file);
            if (!content.Contains(tag.Replace(" />","")))
            {
                content = content.Replace("</ItemGroup>\r\n  <Import", tag + "\r\n</ItemGroup>\r\n  <Import");
                File.WriteAllText(Path, content,Encoding.UTF8);
            }
        }

        public void TryRemovecs(string dir,string file)
        {
    //        string content = File.ReadAllText(Path, Encoding.UTF8);
    //        string tag = string.Format("<Compile Include=\"{0}\\{1}\" />", dir, file);
    //        string tag2 = string.Format("    <Compile Include="Response\VideoMaxidGetResponse.cs">
    //  <SubType>Code</SubType>
    //</Compile>");
    //        if (!content.Contains(tag.Replace("/>", "")))
    //        {
    //            content.Replace(tag, tag + "\r\n</ItemGroup>");
    //        }
        }

    }
}
